﻿using System;
using System.ComponentModel;
using System.Drawing.Design;
using System.Windows.Forms;
using Argos.Scheduling;
using Argos.Windows.Forms;

namespace Argos.Design
{
	public class ScheduleTypeEditor : UITypeEditor
	{

		public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
		{
			using (ScheduleEditorDialog dlg = new ScheduleEditorDialog())
			{
				if (value is Schedule)
				{
					dlg.SelectedSchedule = (Schedule)value;
				}

				if (dlg.ShowDialog() == DialogResult.OK)
				{
					return dlg.SelectedSchedule;
				}
			}

			return value;
		}

		public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext context)
		{
			return UITypeEditorEditStyle.Modal;
		}

	}
}
